home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 10.9 KB | 331 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWCmd.h
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWCMD_H
- #define FWCMD_H
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef FWODTYPS_H
- #include "FWODTyps.h"
- #endif
-
- #ifndef SOM_ODUndo_xh
- #include <Undo.xh>
- #endif
-
- //==============================================================================
- // Forward Declarations
- //==============================================================================
-
- class FW_CPart;
- class FW_CFrame;
- class FW_CString;
- class FW_CPresentation;
- class ODUndo;
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- #define FW_kCanUndo TRUE
- #define FW_kCantUndo FALSE
-
- //==============================================================================
- // class FW_CCommand
- //==============================================================================
-
- class FW_CCommand
- {
- public:
- FW_DECLARE_AUTO(FW_CCommand)
-
- public:
-
- //------------------------------------------------------------------------
- // --- Initialization/Destruction ---
-
- FW_CCommand(Environment* ev,
- ODCommandID id,
- FW_CFrame* frame,
- FW_Boolean canUndo);
- virtual ~ FW_CCommand();
-
- //------------------------------------------------------------------------
- // --- Command API ---
-
- FW_Boolean Execute(Environment* ev, FW_Boolean deleteIfNotUndoable = TRUE);
- // Execute the command by calling DoIt,
- // and take care of OpenDoc Undo/Redo paperwork if necessary.
- // Return TRUE if the command is on the OpenDoc undo stack. The command
- // is automatically deleted if not undoable unless deleteIfNotUndoable is
- // set to false
-
- virtual void DoIt(Environment* ev) = 0;
- // Must be overridden by all commands
-
- //------------------------------------------------------------------------
- // --- API for Undo-able Commands ---
-
- virtual void UndoIt(Environment* ev);
- virtual void RedoIt(Environment* ev);
- // Undo-able commands must override
- // Default does nothing
-
- virtual void CommitDone(Environment* ev);
- // Called just before the command is deleted.
- // doneState values are kODDone or kODRedone (ODTypes.h)
- // Default calls FreeUndoState
-
- virtual void CommitUndone(Environment* ev);
- // Called just before the command is deleted.
- // doneState value is kODUndone (ODTypes.h)
- // Default calls FreeRedoState
-
- virtual void SaveUndoState(Environment* ev);
- virtual void SaveRedoState(Environment* ev);
- // Save state of data for later undo and redo
- // Default does nothing
-
- virtual void FreeUndoState(Environment* ev);
- virtual void FreeRedoState(Environment* ev);
- // delete data saved for undo and redo
- // Default does nothing
-
- //------------------------------------------------------------------------
- // --- New API ---
- public:
- ODActionType GetActionType(Environment* ev) const;
-
- FW_Boolean GetCanUndo(Environment* ev) const;
- void SetCanUndo(Environment* ev, FW_Boolean canUndo);
-
- FW_Boolean GetCausesChange(Environment* ev) const;
- void SetCausesChange(Environment* ev, FW_Boolean causesChange);
-
- ODCommandID GetCommandID(Environment* ev) const;
- void SetCommandID(Environment* ev, ODCommandID id);
-
- ODName* GetUndoString(Environment* ev);
- ODName* GetRedoString(Environment* ev);
-
- ODUndo* GetUndo(Environment* ev) const;
-
- FW_CPresentation* GetPresentation(Environment* ev) const;
- FW_CFrame* GetSourceFrame(Environment* ev) const;
- FW_CFrame* GetFrame(Environment* ev) const;
- FW_CPart* GetPart(Environment* ev) const;
-
- FW_Boolean HasAddedAction(Environment* ev) const;
-
- void SetActionType(Environment* ev, ODActionType actionType);
-
- protected:
- void SetMenuStrings(Environment* ev,
- const FW_CString& undoString,
- const FW_CString& redoString);
- void SetMenuStrings(Environment* ev,
- char* undoChars,
- char* redoChars);
- void SetMenuStringsFromResource(Environment* ev,
- short stringResourceID,
- short undoStringID,
- short redoStringID);
- // Call one of these to set up menu strings for Undo and Redo
-
- void AddAction(Environment* ev,
- ODActionType actionType,
- octet* dataPtr,
- unsigned long dataSize,
- ODName* undoActionLabel,
- ODName* redoActionLabel);
- // Call ODUndo::AddActionToHistory; used for transactions
-
- FW_Boolean IsOKtoEdit(Environment* ev);
- // Checks whether it's OK to change this part and frame
-
- //------------------------------------------------------------------------
- // Implementation Only
- //
- private:
- void PrivLoadDefaultUndoStrings(Environment* ev);
- void PrivDisposeUndoStrings();
-
- //------------------------------------------------------------------------
- // --- Data Members ---
- private:
- FW_Boolean fCanUndo; // Default = TRUE
- FW_Boolean fCausesChange; // Default = TRUE
- ODCommandID fCommandID;
- ODActionType fActionType; // Default = kODSingleAction
-
- ODName* fUndoString; // string for Undo menu item
- ODName* fRedoString; // string for Redo menu item
-
- FW_CPart* fPart;
- FW_CFrame* fFrame; // Original Command Frame (might not be valid during Undo/Redo)
- FW_CPresentation* fPresentation;
- FW_CFrame* fSourceFrame;
-
- ODUndo* fUndo;
- FW_Boolean fHasAddedAction; // TRUE if this command has called AddAction
-
- // Don't allow commands to be copied or returned from functions
- FW_CCommand(const FW_CCommand& command); // Copy constructor
- FW_CCommand& operator=(const FW_CCommand& command); // Assignment operator
- };
-
- //========================================================================================
- // FW_CCommand Inlines
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetActionType
- //----------------------------------------------------------------------------------------
- inline ODActionType FW_CCommand::GetActionType(Environment*) const
- {
- return fActionType;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetCanUndo
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CCommand::GetCanUndo(Environment*) const
- {
- return fCanUndo;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SetCanUndo
- //----------------------------------------------------------------------------------------
- inline void FW_CCommand::SetCanUndo(Environment*, FW_Boolean canUndo)
- {
- fCanUndo = canUndo;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetCausesChange
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CCommand::GetCausesChange(Environment*) const
- {
- return fCausesChange;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SetCausesChange
- //----------------------------------------------------------------------------------------
- inline void FW_CCommand::SetCausesChange(Environment*, FW_Boolean causesChange)
- {
- fCausesChange = causesChange;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetCommandID
- //----------------------------------------------------------------------------------------
- inline ODCommandID FW_CCommand::GetCommandID(Environment*) const
- {
- return fCommandID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SetCommandID
- //----------------------------------------------------------------------------------------
- inline void FW_CCommand::SetCommandID(Environment*, ODCommandID id)
- {
- fCommandID = id;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetUndoString
- //----------------------------------------------------------------------------------------
- inline ODName* FW_CCommand::GetUndoString(Environment* ev)
- {
- if (!fUndoString)
- PrivLoadDefaultUndoStrings(ev);
- return fUndoString;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetRedoString
- //----------------------------------------------------------------------------------------
- inline ODName* FW_CCommand::GetRedoString(Environment* ev)
- {
- if (!fRedoString)
- PrivLoadDefaultUndoStrings(ev);
- return fRedoString;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetUndo
- //----------------------------------------------------------------------------------------
- inline ODUndo* FW_CCommand::GetUndo(Environment*) const
- {
- return fUndo;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::HasAddedAction
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CCommand::HasAddedAction(Environment*) const
- {
- return fHasAddedAction;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SetActionType
- //----------------------------------------------------------------------------------------
- inline void FW_CCommand::SetActionType(Environment*, ODActionType actionType)
- {
- fActionType = actionType;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetPart
- //----------------------------------------------------------------------------------------
- inline FW_CPart* FW_CCommand::GetPart(Environment*) const
- {
- return fPart;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetFrame
- //----------------------------------------------------------------------------------------
- inline FW_CFrame* FW_CCommand::GetFrame(Environment*) const
- {
- return fFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetSourceFrame
- //----------------------------------------------------------------------------------------
- inline FW_CFrame* FW_CCommand::GetSourceFrame(Environment*) const
- {
- return fSourceFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetPresentation
- //----------------------------------------------------------------------------------------
- inline FW_CPresentation* FW_CCommand::GetPresentation(Environment*) const
- {
- return fPresentation;
- }
-
- #endif
-